admin/init-fs: Add a --modern switch
authorColin Walters <walters@verbum.org>
Tue, 6 Aug 2019 01:59:38 +0000 (01:59 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 8 Aug 2019 20:02:11 +0000 (20:02 +0000)
This skips creating the default stuff in the physical sysroot.
I don't recall why I did that to be honest; it originated with
the first commit of this file.  It might not have ever been
necessary.

In any case, it's not necessary now with Fedora CoreOS, so
prune it and let's have a clean `/`.

Keep the old behavior by default though to avoid breaking anyone.

Closes: #1894
Approved by: ajeddeloh

src/ostree/ot-admin-builtin-init-fs.c
tests/admin-test.sh

index cca63a62bf340ac7802beb4327a16aa780d4d2cf..cb1e1b69fffaae20a4bba3e1e3805439c4039212 100644 (file)
 
 #include <glib/gi18n.h>
 
+static gboolean opt_modern;
+
 static GOptionEntry options[] = {
+  { "modern", 0, 0, G_OPTION_ARG_NONE, &opt_modern, "Only create /boot and /ostree", NULL },
   { NULL }
 };
 
@@ -58,26 +61,39 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invoca
   if (!glnx_opendirat (AT_FDCWD, sysroot_path, TRUE, &root_dfd, error))
     return FALSE;
 
-  const char *normal_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"};
-  for (guint i = 0; i < G_N_ELEMENTS (normal_toplevels); i++)
-    {
-      if (!glnx_shutil_mkdir_p_at (root_dfd, normal_toplevels[i], 0755,
-                                   cancellable, error))
-        return FALSE;
-    }
-
-  if (!glnx_shutil_mkdir_p_at (root_dfd, "root", 0700,
-                               cancellable, error))
+  /* It's common to want to mount this outside of a deployment as well */
+  if (!glnx_shutil_mkdir_p_at (root_dfd, "boot", 0755, cancellable, error))
     return FALSE;
 
-  if (!glnx_shutil_mkdir_p_at (root_dfd, "tmp", 01777,
-                               cancellable, error))
-    return FALSE;
-  if (fchmodat (root_dfd, "tmp", 01777, 0) == -1)
+  /* See https://github.com/coreos/coreos-assembler/pull/688
+   * For Fedora CoreOS at least, we have this now to the point where we don't
+   * need this stuff in the physical sysroot.  I'm not sure we ever really did,
+   * but to be conservative, make it opt-in to the new model of just boot/ and ostree/.
+   */
+  if (!opt_modern)
     {
-      glnx_set_prefix_error_from_errno (error, "chmod: %s", "tmp");
-      return FALSE;
+      const char *traditional_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"};
+      for (guint i = 0; i < G_N_ELEMENTS (traditional_toplevels); i++)
+        {
+          if (!glnx_shutil_mkdir_p_at (root_dfd, traditional_toplevels[i], 0755,
+                                      cancellable, error))
+            return FALSE;
+        }
+
+      if (!glnx_shutil_mkdir_p_at (root_dfd, "root", 0700,
+                                  cancellable, error))
+        return FALSE;
+
+      if (!glnx_shutil_mkdir_p_at (root_dfd, "tmp", 01777,
+                                  cancellable, error))
+        return FALSE;
+      if (fchmodat (root_dfd, "tmp", 01777, 0) == -1)
+        {
+          glnx_set_prefix_error_from_errno (error, "chmod: %s", "tmp");
+          return FALSE;
+        }
     }
+
   g_autoptr(GFile) dir = g_file_new_for_path (sysroot_path);
   g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (dir);
   if (!ostree_sysroot_ensure_initialized (sysroot, cancellable, error))
index 31e969c2dde1ee9c4d07e2301895e1505d512fe9..0defebc0769522550611d35afd5d3e763d57a507 100644 (file)
 
 set -euo pipefail
 
-echo "1..$((26 + ${extra_admin_tests:-0}))"
+echo "1..$((27 + ${extra_admin_tests:-0}))"
+
+mkdir sysrootmin
+${CMD_PREFIX} ostree admin init-fs --modern sysrootmin
+assert_has_dir sysrootmin/boot
+assert_has_dir sysrootmin/ostree/repo
+assert_not_has_dir sysrootmin/home
+rm sysrootmin -rf
+echo "ok init-fs --modern"
 
 function validate_bootloader() {
     cd ${test_tmpdir};
@@ -48,7 +56,7 @@ orig_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)
 ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmaster/x86_64-runtime
 rev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
 export rev
-# This initial deployment gets kicked off with some kernel arguments 
+# This initial deployment gets kicked off with some kernel arguments
 ${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmaster/x86_64-runtime
 new_mtime=$(stat -c '%.Y' sysroot/ostree/deploy)
 assert_not_streq "${orig_mtime}" "${new_mtime}"